﻿// -----------------------------------------------------------------------
// <copyright file="ImageEnchance.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace LastVersionOfIpPackage.ImageOperations
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using Enum_needed;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ImageEnchance : IImageEnchance
    {
        /// <summary>
        /// static object of this class to use this without create object to use this without create object
        /// </summary>
        private static ImageEnchance newImageEnchanemwnt = new ImageEnchance();

        /// <summary>
        /// Gets or sets the new image enchanemwnt.
        /// </summary>
        /// <value>
        /// The new image enchanemwnt.
        /// </value>
        public static ImageEnchance NewImageEnchanemwnt
        {
            get { return ImageEnchance.newImageEnchanemwnt; }
            set { ImageEnchance.newImageEnchanemwnt = value; }
        }

        /// <summary>
        /// Open image.
        /// </summary>
        /// <param name="path">The path of image.</param>
        /// <returns>bitmap image</returns>
        public Bitmap Open(string path)
        {
            return Operations.Open.Open1.OpenImage(path);
        }

        /// <summary>
        /// make Resizes in the specified image.
        /// </summary>
        /// <param name="image">The original image.</param>
        /// <param name="newWidth">The new width.</param>
        /// <param name="newHeigth">The new heigth.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Resize(Bitmap image, int newWidth, int newHeigth)
        {
            return Operations.Resize.Resize1.ResizeI(image, null, newWidth, newHeigth);
        }

        /// <summary>
        /// Saves the  image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="path">The path.</param>
        public void Save(Bitmap image, string path)
        {
            Operations.SaveImage.Save1.Save(path, image);
        }

        /// <summary>
        /// Saves as specify type.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="path">The path of save.</param>
        public void SaveAs(Bitmap image, string path) ////type
        {
        }

        /// <summary>
        /// Converts to image from bitmap to another type.
        /// </summary>
        /// <param name="pathInput">The path input image.</param>
        /// <param name="pathOutput">The path output image save.</param>
        public void ConvertTo(string pathInput, string pathOutput) ////type
        {
        }

        /// <summary>
        /// make Translate to the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="transValInX">The trans val in X.</param>
        /// <param name="transValInY">The trans val in Y.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Translate(Bitmap image, int transValInX, int transValInY)
        {
            return Operations.Translation.Translate.Trans_image(image, transValInX, transValInY);
        }

        /// <summary>
        /// make Rotates to the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="angle">The angle of rotate.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Rotate(Bitmap image, double angle)
        {
            return Operations.Rotation.Rotation1.MakeRotate(image, angle);
        }

        /// <summary>
        /// make Grays to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Gray(Bitmap image)
        {
            return Operations.Gray.Gray1.GrayImg(image);
        }

        /// <summary>
        /// Draws the histogram.
        /// </summary>
        /// <param name="colorNeed">The color need.</param>
        /// <param name="image">The image.</param>
        /// <param name="heigthOfImage">The heigth of image output .</param>
        /// <returns>
        /// result histogram
        /// </returns>
        public Bitmap DrawHistogram(ColorNeed colorNeed, Bitmap image, int heigthOfImage)
        {
            try
            {
                long[] result;
                Color c;
                switch (colorNeed)
                {
                    case Enum_needed.ColorNeed.Blue:
                        {
                            result = Operations.Histogram.Histogram1.HistoBlue(image);
                            c = Color.LightBlue;
                            return Operations.Histogram.Histogram1.Draw(result, c, heigthOfImage);
                        }

                    case Enum_needed.ColorNeed.Gray:
                        {
                            result = Operations.Histogram.Histogram1.HistoGray(image);
                            c = Color.LightGray;
                            return Operations.Histogram.Histogram1.Draw(result, c, heigthOfImage);
                        }

                    case Enum_needed.ColorNeed.Green:
                        {
                            result = Operations.Histogram.Histogram1.HistoGreen(image);
                            c = Color.LightGreen;
                            return Operations.Histogram.Histogram1.Draw(result, c, heigthOfImage);
                        }

                    case Enum_needed.ColorNeed.Red:
                        {
                            result = Operations.Histogram.Histogram1.HistoRed(image);
                            c = Color.PaleVioletRed;
                            return Operations.Histogram.Histogram1.Draw(result, c, heigthOfImage);
                        }

                    default:
                        {
                            return null;
                        }
                }
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// make Brigthnesse to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="offset">The offset of brigthness.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Brigthness(Bitmap image, int offset)
        {
            return Operations.HistoOperation.HistorOperation.Britness(offset, image);
        }

        /// <summary>
        /// make Contrast to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="offset">The offset of contrast.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Contrast(Bitmap image, int offset)
        {
            return Operations.HistoOperation.HistorOperation.Contrast(offset, image);
        }

        /// <summary>
        /// make Gamma to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="gammaValue">The gamma value if large than 1 make dark to image else make brigthness off image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Gamma(Bitmap image, double gammaValue)
        {
            return Operations.HistoOperation.HistorOperation.Gamma(gammaValue, image);
        }

        /// <summary>
        /// make Equalization to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Equalization(Bitmap image)
        {
            return Operations.HistoOperation.HistorOperation.Equalization(image);
        }

        /// <summary>
        /// makke Matching to specified destination and source image.
        /// </summary>
        /// <param name="sourceImage">The source image.</param>
        /// <param name="destinationImage">The destination image would have efficient of source image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Matching(Bitmap sourceImage, Bitmap destinationImage)
        {
            return Operations.HistoOperation.HistorOperation.Matching(destinationImage, sourceImage);
        }

        /// <summary>
        /// make Negative to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Negative(Bitmap image)
        {
            return Operations.OneImgOperation.NewNegativeOperation.MakeNegative(image);
        }

        /// <summary>
        /// make Add to specified image1+image2 with size of image1.
        /// </summary>
        /// <param name="image1">The image1.</param>
        /// <param name="image2">The image2.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Add(Bitmap image1, Bitmap image2)
        {
            return Operations.TwoImgOperation.TwoImgOperAddOrSub.Add(image1, image2, 0.5);
        }

        /// <summary>
        /// make Add to specified image1+image2 with size of image1.
        /// </summary>
        /// <param name="image1">The image1.</param>
        /// <param name="image2">The image2.</param>
        /// <param name="factor">The factor.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Add(Bitmap image1, Bitmap image2, double factor)
        {
            return Operations.TwoImgOperation.TwoImgOperAddOrSub.Add(image1, image2, factor);
        }

        /// <summary>
        /// make Sub to specified image1-image2 with size of image1.
        /// </summary>
        /// <param name="image1">The image1.</param>
        /// <param name="image2">The image2.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Sub(Bitmap image1, Bitmap image2)
        {
            return Operations.TwoImgOperation.TwoImgOperAddOrSub.Sub(image1, image2);
        }

        /// <summary>
        /// make Quantization to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="mask">The mask need apply.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Quantization(Bitmap image, int mask)
        {
            return Operations.Quantization.Quantization1.QuantizationImg(image, mask);
        }

        /// <summary>
        /// make Mean the filter to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="meanOrSigma">The mean or sigma.</param>
        /// <param name="type">The type of smoothing.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap SmoothingFilter(Bitmap image, double meanOrSigma, SmoothingType type)
        {
            return Operations.Smoothing.Smoothing1.MakeSmoothing(image, meanOrSigma, type);
        }

        /// <summary>
        /// make Mean the filter to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="meanOrSigma">The mean or sigma.</param>
        /// <param name="d">The d.</param>
        /// <param name="type">The type of smoothing.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap SmoothingFilter(Bitmap image, double meanOrSigma, int d, SmoothingType type)
        {
            return Operations.Smoothing.Smoothing1.MakeSmoothing(image, meanOrSigma, d, type);
        }

        /// <summary>
        /// make Sharpening to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="sharpeningType">My sharpening type.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Sharpening(Bitmap image, DetectionAndSharpingType sharpeningType)
        {
            return Operations.Sharpening.Sharp.MakeSharpening(image, sharpeningType);
        }

        /// <summary>
        /// make Converts to freq.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// freq image
        /// </returns>
        public Bitmap ConvertToFreq(Bitmap image)
        {
            return Operations.MATLAPOper.MatlapOper.CalcuMagnitudeTOImag(image);
        }

        /// <summary>
        /// make Convert to spatial.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap ConvertToSpatial(Bitmap image)
        {
            return Operations.MATLAPOper.MatlapOper.ConvertToSpatialDomain(image);
        }

        /// <summary>
        /// Converts to freq of specified color in image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="myColor">color need return.</param>
        /// <returns>imagw of maguitude of this color</returns>
        public Bitmap ConvertToFreq(Bitmap image, ColorNeed myColor)
        {
            return Operations.MATLAPOper.MatlapOper.CalcuMagnitudeTODetemineColor(image, myColor);
        }

        /// <summary>
        /// make HPF.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="filterTypeNeed">The filter type need.</param>
        /// <param name="maskTypeNeed">The mask type need.</param>
        /// <param name="d0">The distance between centar and point need make filter From it in HPF , LPF , Notch ,Band.</param>
        /// <param name="order">The order if you use gaussian else make it null or 0.</param>
        /// <param name="uc">The uc.</param>
        /// <param name="vc">The vc.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap FilterOrRemoveNoiseFreq(Bitmap image, Enum_needed.FilterType filterTypeNeed, TypeOfMask maskTypeNeed, double d0, double order, double uc, double vc)
        {
            if (filterTypeNeed == FilterType.NotchPass || filterTypeNeed == FilterType.NotchReject)
            {
               return Operations.MATLAPOper.MatlapOper.CalcuTOIMGPass(image, filterTypeNeed, maskTypeNeed, d0, order, uc, vc);
            }
            else
            {
                return Operations.MATLAPOper.MatlapOper.CalcuTOIMGPass(image, filterTypeNeed, maskTypeNeed, d0, order);
            }
        }

        /// <summary>
        /// Adds the noise to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="ps">The ps probablity of salt.</param>
        /// <param name="pp">The pp probablity of paper.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap AddSaltAndPepperNoise(Bitmap image, double ps, double pp)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddSaltAndPepperNoise(image, ps, pp);
        }

        /// <summary>
        /// Adds the periodic noise.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="amplitude">The amplitude of noise.</param>
        /// <param name="frequencyInX">The frequency in X number of repetions in x axis.</param>
        /// <param name="frequenceInY">The frequence in Y number of repetions in y axis.</param>
        /// <param name="px">The px phase shift in x axis.</param>
        /// <param name="py">The py phase shift in y axis.</param>
        /// <returns>noised image</returns>
        public Bitmap AddPeriodicNoise(Bitmap image, double amplitude, double frequencyInX, double frequenceInY, double px, double py)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddPeriodicNoise(image, amplitude, frequencyInX, frequenceInY, px, py);
        }

        /// <summary>
        /// Adds the gaussian noise.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="mean">The mean of noise added.</param>
        /// <param name="sigma">The sigma.</param>
        /// <param name="precentage">The precentage of noise.</param>
        /// <returns>noised image</returns>
        public Bitmap AddGaussianNoise(Bitmap image, double mean, double sigma, double precentage)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddGaussianNoise(image, mean, sigma, precentage);
        }

        /// <summary>
        /// Adds the rayleigh noise.
        /// </summary>
        /// <param name="image">The image need add to it noise.</param>
        /// <param name="a">the A.</param>
        /// <param name="b">The b.</param>
        /// <param name="precentage">The precentage of noise.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap AddRayleighNoise(Bitmap image, double a, double b, double precentage)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddRayleighNoise(image, a, b, precentage);
        }

        /// <summary>
        /// Adds the gamma noise.
        /// </summary>
        /// <param name="image">The image need add to it noise.</param>
        /// <param name="a">the A.</param>
        /// <param name="b">The b.</param>
        /// <param name="precentage">The precentage of noise.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap AddGammaNoise(Bitmap image, double a, int b, double precentage)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddGammaNoise(image, a, b, precentage);
        }

        /// <summary>
        /// Adds the noise to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="a">A start value of noise added.</param>
        /// <param name="b">The b the end value of noise added.</param>
        /// <param name="precentage">The precentage of noise in image.</param>
        /// <returns>
        /// noised image
        /// </returns>
        public Bitmap AddUniformNoise(Bitmap image, int a, int b, double precentage)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddUniformNoise(image, a, b, precentage);
        }

        /// <summary>
        /// Adds the exponential noise.
        /// </summary>
        /// <param name="image">The image need add to it noise.</param>
        /// <param name="landa">The landa of noise expon.</param>
        /// <param name="percentage">The percentage of noise.</param>
        /// <returns>
        /// noised image
        /// </returns>
        public Bitmap AddExponentialNoise(Bitmap image, double landa, double percentage)
        {
            return Operations.NoiseAdded.NoiseAdded1.AddExponentialNoise(image, landa, percentage);
        }

        /// <summary>
        /// Removes the noise from specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="myTypeOfFilter">My type of filter.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap RemoveNoise(Bitmap image, int maskSize, OrderStatisticType myTypeOfFilter)
        {
            return Operations.OrderdFilter.Instance.ApplyFiltersOrderStaticsAndMeanGeom(image, maskSize, myTypeOfFilter);
        }

        /// <summary>
        /// apply Morphological to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="myMorphologyType">Type of my morphology need.</param>
        /// <param name="setB">The set B.</param>
        /// <param name="thresholdValue">The threshold value.</param>
        /// <param name="original">The original point in set b.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Morphological(Bitmap image, MorphologyType myMorphologyType, int[,] setB, int thresholdValue, Point original)
        {
            return Operations.Morphology.Instance.MakeMorphology(image, myMorphologyType, setB, thresholdValue, original);
        }

        /// <summary>
        /// make Thresholds the specified image.
        /// </summary>
        /// <param name="image">The original image.</param>
        /// <param name="thresholdValue">The threshold value.</param>
        /// <returns>
        /// modified image
        /// </returns>
        public Bitmap Threshold(Bitmap image, int thresholdValue)
        {
            return Operations.HistoOperation.HistorOperation.Threshold(image, thresholdValue);
        }

        /// <summary>
        /// make Edge detection to specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="myEdgeType">Type of my edge.</param>
        /// <returns>modified image</returns>
        public Bitmap EdgeDetection(Bitmap image, DetectionAndSharpingType myEdgeType)
        {
            return Operations.EdgeDetection.EdgeDetection1.MakeEdgeDetection(image, myEdgeType);
        }

        /// <summary>
        /// Locals  histogram equalization.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="maskSize">Size of the mask.</param>
        /// <returns>The new image </returns>
        public Bitmap LocalHistogramEqualization(Bitmap image, int maskSize)
        {
            return Operations.MATLAPOper.MatlapOper.LocalHistogramEqualization(image, maskSize);
        }

        /// <summary>
        /// Locals statistics.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="e">The e.</param>
        /// <param name="k0">The k0.</param>
        /// <param name="k1">The k1.</param>
        /// <param name="k2">The k2.</param>
        /// <returns>the new image</returns>
        public Bitmap LocalStatistics(Bitmap image, int maskSize, int e, double k0, double k1, double k2)
        {
            return Operations.MATLAPOper.MatlapOper.LocalStatistics(image, maskSize, e, k0, k1, k2);
        }
    }
}
